//
//  CMMainCell.m
//  CraneMachine
//
//  Created by ice on 2017/10/31.
//  Copyright © 2017年 ICE. All rights reserved.
//

#import "CMMainCell.h"

@interface CMMainCell ()

/**  图片 */
@property (strong, nonatomic)  UIImageView *goodsImageView;
@property (strong, nonatomic)  UIButton *modelLabel;// 模式
@property (strong, nonatomic)  UILabel *nameLabel;
@property (strong, nonatomic)  UILabel *deviceLabel;// 设备
@property (strong, nonatomic)  UIImageView *priceImageView;
@property (strong, nonatomic)  UILabel *priceLabel;
//@property (strong, nonatomic)  UIImageView *stateImageView;
@property (strong, nonatomic)  UILabel *stateLabel;
@end

@implementation CMMainCell

- (void)setMainCellFModel:(QYGMainCellFrameModel *)mainCellFModel{
    
    _mainCellFModel = mainCellFModel;
    self.goodsImageView.frame = mainCellFModel.goodsImageViewF;
    self.nameLabel.frame = mainCellFModel.nameLabelF;
    self.priceLabel.frame = mainCellFModel.priceLabelF;
    self.priceImageView.frame = mainCellFModel.priceImageViewF;
    self.deviceLabel.frame = mainCellFModel.deviceLabelF;
    self.stateLabel.frame = mainCellFModel.stateLabelF;
    
    self.nameLabel.text = mainCellFModel.dollListModel.ware_name;
    [self.goodsImageView setImageWithURL:mainCellFModel.dollListModel.ware_image placeholder:[UIImage imageNamed:@"img_fail"]];
    self.deviceLabel.text = mainCellFModel.dollListModel.name;
    self.priceLabel.text =  [NSString stringWithFormat:@"%ld金币/次",mainCellFModel.dollListModel.coin];
//    [self.priceLabel sizeToFit];
    //status:0-空闲，1-游戏中,2-故障状态
    switch (mainCellFModel.dollListModel.device_status) {
        case 0:
            self.stateLabel.text = @"空闲中";
            self.stateLabel.backgroundColor = [UIColor colorWithHex:@"29c956"];
            break;
        case 1:
            self.stateLabel.text = @"游戏中";
            self.stateLabel.backgroundColor = [UIColor colorWithHex:@"ff8b3d"];
            break;
        case 2:
            self.stateLabel.text = @"维护中";
            break;
        default:
            self.stateLabel.text = @"";
            break;
    }
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if(self){
        
        [self viewWithcornerRadius:10 borderWidth:0.5 borderColor:[UIColor colorWithHex:@"e5e5e5"] backgroundColor:[UIColor whiteColor]];
        [self addSubview:self.goodsImageView];
        [self addSubview:self.deviceLabel];
//        [self addSubview:self.modelLabel];
        [self addSubview:self.priceLabel];
        [self addSubview:self.nameLabel];
        [self addSubview:self.priceImageView];
        [self addSubview:self.stateLabel];
    }
    return self;
    
}

- (UILabel *)stateLabel{
    if(!_stateLabel){
        _stateLabel = [SGUtil newLabelWithFont:ScaleFont(12) textColor:[UIColor whiteColor] text:@"热玩中"];
        _stateLabel.textAlignment = NSTextAlignmentCenter;
        [_stateLabel viewWithcornerRadius:3 borderWidth:1 borderColor:[UIColor clearColor]];
    }
    return _stateLabel;
}
- (UILabel *)deviceLabel{
    if(!_deviceLabel){
        _deviceLabel = [UILabel labelWithText:@"设备" setFont:ScaleFont(12) setTextColor:[UIColor colorWithHex:@"999999"] setTextAlignment:NSTextAlignmentLeft];
        _deviceLabel.numberOfLines = 1;
    }
    return _deviceLabel;
}
- (UILabel *)priceLabel{
    if(!_priceLabel){
        _priceLabel = [UILabel labelWithText:@"0金币/次" setFont:ScaleFont(12) setTextColor:[UIColor colorWithHex:@"999999"] setTextAlignment:NSTextAlignmentRight];
//        _priceLabel.backgroundColor = [UIColor yellowColor];
        _priceLabel.numberOfLines = 1;
    }
    return _priceLabel;
}
- (UIImageView *)priceImageView{
    
    if(!_priceImageView){
        
        _priceImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"droll_jb"]];
//        _priceImageView.backgroundColor = [UIColor yellowColor];
    }
    return _priceImageView;
}
- (UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [SGUtil newLabelWithFont:ScaleFont(15) textColor:[UIColor colorWithHex:@"1A1A1A"] text:@"产品名称"];
        _nameLabel.numberOfLines = 1;
    }
    return _nameLabel;
}
- (UIButton *)modelLabel{
    if(!_modelLabel){
        _modelLabel  = [UIButton buttonWithType:UIButtonTypeCustom];
        [_modelLabel setBackgroundImage:[UIImage imageNamed:@"droll_wxms"] forState:UIControlStateNormal];
    }
    return _modelLabel;
}

- (UIImageView *)goodsImageView{
    
    if(!_goodsImageView){
        _goodsImageView = [[UIImageView alloc] init];
        _goodsImageView.contentMode = UIViewContentModeScaleAspectFill;
        _goodsImageView.layer.masksToBounds = YES;
    }
    return _goodsImageView;
}
@end
